<script src="/themes/ace/assets/js/jquery.nestable.min.js"></script>
<div id="{{ id }}" class="dd dd-draghandle">
{% if title_display is empty %}
{% set title_display = false %}
{% endif %}

	{% if title == null AND title_display == true %}
	<h4 class="header smaller lighter grey">{{ title }}</h4>
	<div class="space-8"></div>
	{% endif %}
	{%- macro hierarchical_list(data,hierarchy,me) %}
	<ol class="dd-list">
		{%- for key, value in hierarchy %} 
		<li data-id="{{ key }}" class="dd-item dd2-item">
			<div class="dd-handle dd2-handle">
				<i class="normal-icon icon-move bigger-130"></i> <i
					class="drag-icon icon-move pink bigger-125"></i>
			</div>
			<div class="dd2-content">
				{{ data[key]['name'] }}
				 <a target="_black" href="{{ data[key]['nav']['see']['href'] }}">查看</a>&nbsp;|&nbsp;
				 <a class="ajax-load-link" hrefbox="#right_handle" href="{{ me.url.get(['for':'adminUserRoleEditor','id':key]) }}">编辑</a>&nbsp;|&nbsp;
				 <a class="ajax-load-link" hrefbox="#main-content" href="{{ me.url.get(['for':'adminUserRoleDelete','id':key]) }}">删除</a>
			</div> {% if key != value %}{{ hierarchical_list(data,value,me) }}{% endif %}
		</li>{%- endfor %}
	</ol>
	{%- endmacro %}

	<?php if (is_array($data) && is_array($hierarchy)) { ?>
	{{ hierarchical_list(data,hierarchy,this) }}
	<button type="submit" class="save_sort btn btn-success btn-block">保存排序</button>
	<?php }else { ?>
	该菜单还没有任何的菜单项。
	<?php } ?>
	</div>

	<script type="text/javascript">
	(function($){
				$('#{{ id }}').nestable();
			    $('.dd-handle a').on('mousedown', function(e){
					e.stopPropagation();
				});
				//$('[data-rel="tooltip"]').tooltip();
				$("#{{ id }} .save_sort").click(function(){
					var e = $("#{{ id }}");
					var list   = e.length ? e : $(e.target),
				            output = list.data('output');
				        if (window.JSON) {
				            var postJson = window.JSON.stringify(list.nestable('serialize'));
				            $.post("{{ url }}",{rh:postJson},function(data){
				            	$(".main-content").html(data);
				            	$.notice('提交成功');
				            },"html");
				        } else {
				            alert('您的浏览器不安全，不支持本系统.');
				        }
				})

				
		})(jQuery); 
</script>